import React from 'react';
import { connect } from 'dva';
import router from 'umi/router';

import { Table, Button } from 'antd';

import Link from 'umi/link'

const formPath = '/AccountConfig/AccountJournalForm';
const linePath = '/AccountConfig/AccountJournal';


@connect(({ accountJournal }) => ({ accountJournal }))
class List extends React.Component {
  state = {
  }

  treeview = [
      {
        title: '',
        dataIndex: '_',
        render: (_, { id }) => {
          return <Link to={`${linePath}?id=${id}`}>查看</Link>;
        },
      },
      { title: '代码', dataIndex: 'code', },
      { title: '名称', dataIndex: 'name', },
      { title: '类型', dataIndex: 'type', },
      { title: '默认借方科目', dataIndex: 'default_debit_account_id.code', },
      { title: '默认借方科目', dataIndex: 'default_debit_account_id.name', },
      { title: '默认贷方科目', dataIndex: 'default_credit_account_id.code', },
      { title: '默认贷方科目', dataIndex: 'default_credit_account_id.name', },
      { title: '银行', dataIndex: 'bank_id.name', },
      { title: '账户', dataIndex: 'bank_acc_number', },
  ]

  async componentDidMount() {
    const { dispatch } = this.props;
    await dispatch({
      type: 'accountJournal/search',
      payload: {domain:[['type','in',['cash','bank']],], },

    });

  }

  gotoForm() {
      router.push(formPath);
  }

  render() {
    const { accountJournal: { recordsList } } = this.props;

    return (
      <div>
        <div>公司每个银行账号，对应一个资金账簿</div>
        <div>收付款时，选择资金账簿就是选择账号</div>
        <div>出纳配置账簿，可以新增编辑，不能删除。</div>
        <Button onClick={()=>this.gotoForm()}>新建</Button>
        <Table columns={this.treeview} dataSource={recordsList} rowKey="id" />

      </div>
    );
  }
}

export default List;





